package com.guidecaptain.java.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.guidecaptain.java.mapper.UserMapper;
import com.guidecaptain.java.model.pojo.User;
import com.guidecaptain.java.service.UserService;

@Service("userService")
public class UserServiceImpl implements UserService {
	@Autowired
	private UserMapper userMapper;

	/**
	 * @param
	 * @return userId
	 */
	@Override
	public int insertUser(User user) {
		this.userMapper.insertUser(user);
		return user.getUserId();
	}

	/**
	 * @param
	 * @return
	 */
	@Override
	public int deleteUser(int userId) {

		return userMapper.deleteUser(userId);
	}

	/**
	 * @param
	 * @return
	 */
	@Override
	public int updateUser(User user) {
		int i = userMapper.updateUser(user);
		System.out.println(i);
		return i;
	}

	@Override
	public User login(String username, String psw) {
		User user = new User();
		user.setUsername(username);
		user = userMapper.queryUser(user);
		if (user != null && user.getPsw().equals(psw)) {
			return user;
		}
		return null;
	}

	/**
	 * 根据用户ID查找用户
	 * 
	 * @param
	 * @return
	 */
	@Override
	public User queryUser(int userId) {
		User user = new User();
		user.setUserId(userId);
		return userMapper.queryUser(user);
	}

	/**
	 * 根据用户名查找用户
	 * 
	 * @param
	 * @return
	 */
	@Override
	public User queryUser(String username) {
		User user = new User();
		user.setUsername(username);
		return userMapper.queryUser(user);
	}

	/**
	 * @param
	 * @return
	 */
	@Override
	public List<User> queryUserList() {

		return userMapper.queryUserList();
	}

}
